<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">


    <link rel="stylesheet" href="/assets/css/login.css">
    <script src="/static/js/jquery.js"></script>
    <script src="/assets/layui.js"></script>
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/assets/css/layui.css">
    <title>管理后台</title>
</head>
<body class="login-wrap">
<div class="login-container">
    <form class="login-form" action="login_ok" method="post">
        @csrf
        <input type="hidden" id="_token" value="<?php echo csrf_token();?>">
        <div class="input-group">
            <input type="text" id="username" name="username" class="input-field">
            <label for="username" class="input-label">
                <span class="label-title">用户名</span>
            </label>
        </div>
        <div class="input-group">
            <input type="password" id="password" name="password" class="input-field">
            <label for="password" class="input-label">
                <span class="label-title">密码</span>
            </label>
        </div>
        <button type="submit" id="submit" class="login-button">登录<i class="ai ai-enter"></i></button>
    </form>
</div>
</body>
<script src="/index.js" data-main="login"></script>
</html>
<script>
    $(function(){
        $('#submit').click(function () {
            $.get({
                url:"login_ok",
                data:'username='+$('#username').val()+'&password='+$('#password').val(),
                success:function (data) {
                    layui.use('layer', function(){
                        var layer = layui.layer;
                        if(data.code=='1') {
                            layer.open({
                                title: '登录成功'
                                , skin: 'msg'
                                , content: data.name
                                , yes: function () {
                                    location.href = data.url;
                                }
                            });
                        }else if(data.code=='-1'){
                            layer.open({
                                title: '登录失败'
                                , skin: 'msg'
                                , content: data.name
                                , yes: function () {
                                    location.href = '/adminlogin';
                                }
                            });
                        }else if (data.code=='-2'){
                            layer.open({
                                title: '登录失败'
                                , skin: 'msg'
                                , content: data.name
                                , yes: function () {
                                    location.href = '/adminlogin';
                                }
                            });
                        }else {
                            layer.open({
                                title: '登录失败'
                                , skin: 'msg'
                                , content: data.name
                                , yes: function () {
                                    location.href = '/adminlogin';
                                }
                            });
                        }
                    });
                }
            });
            return false;
        })
    });
</script>
